package com.shengde.jinwawaforleader.model.homePage.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.shengde.jinwawaforleader.R;

import java.util.List;

/**
 * Created by JYQ on 2017/1/9 0009.
 */

public class GridViewAdapter extends BaseAdapter {
	private Context context;
	private List<Bitmap> list;
	LayoutInflater layoutInflater;
	private ImageView mImageView;

	public GridViewAdapter(Context context, List<Bitmap> list) {
		this.context = context;
		this.list = list;
		layoutInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list.size()+1;//注意此处
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		convertView = layoutInflater.inflate(R.layout.grid_item, null);
		mImageView = (ImageView) convertView.findViewById(R.id.item);
		if (position < list.size()) {
			mImageView.setImageBitmap(list.get(position));
		}else{
			if (list.size()==9){
				mImageView.setVisibility(View.GONE);
			}
			mImageView.setBackgroundResource(R.drawable.add_photo);//最后一个显示加号图片
		}
		return convertView;
	}

}
